using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Support.V4.App;
using Android.Views;
using Android.Widget;
using Android.Util;

namespace CPXamarin
{
    public class CustomTabAdapter: FragmentPagerAdapter
    {
        private SparseArray<IScrollTabHolder> mScrollTabHolders;
        private string[] Titles = {"Profile", "Reputation", "Bookmarks", "Articles","Blogs","Tips"," MyQuestion","MyAnswer","Message"};
        private IScrollTabHolder mListener;
        public CustomTabAdapter(Android.Support.V4.App.FragmentManager fm) : base(fm)
        {
            mScrollTabHolders = new SparseArray<IScrollTabHolder>();
        }

        public void SetTabHolderScrollingContent(IScrollTabHolder listener)
        {
            mListener = listener;
        }

        public override Java.Lang.ICharSequence GetPageTitleFormatted(int position)
        {
            return new Java.Lang.String(Titles[position]);
        }

        public override Android.Support.V4.App.Fragment GetItem(int position)
        {
            ScrollTabHolderFragment fragment = (ScrollTabHolderFragment)ArrayFragment.NewInstance(position);
            mScrollTabHolders.Put(position, fragment);
            if (mListener != null)
            {
                fragment.SetScrollTabHolder(mListener);
            }

            return  fragment;
        }

        public override int Count
        {
            get
            {
                return Titles.Length;
            }
        }

        public SparseArray<IScrollTabHolder> GetScrollTabHolders()
        {
            return mScrollTabHolders;
        }
    }
}